﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<skags.Models.PollModels>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Nýjasta könnunin
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<div id="main">
    <h2>Nýjasta könnunin</h2>
    <%
        if (Model == null)
            Response.Write("Engin könnun til.");
        else
        {
%>
    <table border="1" cellpadding="1">
        <tr>
            <th>
                Nr.
            </th>
            <th>
                Spurning
            </th>
            <%
            if (Model.Option1 != null)%>
            <%
            {%>
            <th>
                Svar 1
            </th>
            <%
            }%>


            <%
            if (Model.Option2 != null)%>
            <%
            {%>
            <th>
                Svar 2
            </th>
            <%
            }%>

            <%
            if (Model.Option3 != null)%>
            <%
            {%>
            <th>
                Svar 3
            </th>
            <%
            }%>

            <%
            if (Model.Option4 != null)%>
            <%
            {%>
            <th>
                Svar 4
            </th>
            <%
            }%>

            <%
            if (Model.Option5 != null)%>
            <%
            {%>
            <th>
                Svar 5
            </th>
            <%
            }%>
        </tr>
            
        <tr>
            <td>
                <%:Model.id%>
            </td>
            <td>
                <%:Model.Question%>
            </td>
            <%
            if (Model.Option1 != null)%>
            <%
            {%>
            <td>
                <%:Model.Option1%>
           </td>
           <%
            }%>

           <%
            if (Model.Option2 != null)%>
           <%
            {%>
           <td>
                <%:Model.Option2%>
            </td>
            <%
            }%>

            <%
            if (Model.Option3 != null)%>
            <%
            {%>
            <td>
                <%:Model.Option3%>
            </td>
            <%
            }%>

            <%
            if (Model.Option4 != null)%>
            <%
            {%>
            <td>
                <%:Model.Option4%>
            </td>
            <%
            }%>

            <%
            if (Model.Option5 != null)%>
            <%
            {%>
            <td>
                <%:Model.Option5%>
            </td>
            <%
            }%>
        </tr>           
        </table>
        
        <%
            if (Model.Vote1 == null)
            {
                Model.Vote1 = 0;
            }
        %>
        <%
            if (Model.Vote2 == null)
            {
                Model.Vote2 = 0;
            }
        %>
        <%
            if (Model.Vote3 == null)
            {
                Model.Vote3 = 0;
            }
        %>
        <%
            if (Model.Vote4 == null)
            {
                Model.Vote4 = 0;
            }
        %>
        <%
            if (Model.Vote5 == null)
            {
                Model.Vote5 = 0;
            }
%>

        <%
            if (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5 > 0)%>
        <%
            {%>
            <%
                if (Model.Vote1 > 0)
                {%>
                <p>Svar 1 fékk <%=Model.Vote1%> atkvæði (<%=
                        Math.Round(
                            ((double)
                             ((Model.Vote1)/
                              (double) (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5))*100), 2)%>%)</p>
            <%
                }%>
            <%
                if (Model.Vote2 > 0)
                {%>
                <p>Svar 2 fékk <%=Model.Vote2%> atkvæði (<%=
                        Math.Round(
                            ((double)
                             ((Model.Vote2)/
                              (double) (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5))*100), 2)%>%)</p>
            <%
                }%>
            <%
                if (Model.Vote3 > 0)
                {%>
                <p>Svar 3 fékk <%=Model.Vote3%> atkvæði (<%=
                        Math.Round(
                            ((double)
                             ((Model.Vote3)/
                              (double) (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5))*100), 2)%>%)</p>
            <%
                }%>
            <%
                if (Model.Vote4 > 0)
                {%>
                <p>Svar 4 fékk <%=Model.Vote4%> atkvæði (<%=
                        Math.Round(
                            ((double)
                             ((Model.Vote4)/
                              (double) (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5))*100), 2)%>%)</p>
            <%
                }%>
            <%
                if (Model.Vote5 > 0)
                {%>
                <p>Svar 5 fékk <%=Model.Vote5%> atkvæði (<%=
                        Math.Round(
                            ((double)
                             ((Model.Vote5)/
                              (double) (Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5))*100), 2)%>%)</p>
            <%
                }%>
        <%
            }%>
        <%
            else if (Equals(Model.Vote1 + Model.Vote2 + Model.Vote3 + Model.Vote4 + Model.Vote5, 0))
            {%>
                <p>Engin atkvæði hafa verið greidd</p> 
           <%
            }%>
                <a href="../../Home/Index">Á forsíðu</a><br />
                <a href="/Poll/Polls">Skoða eldri kannanir</a>
        <%
        }
        %>
    </div>
</asp:Content>